package systemConfigRequest

import (
	"arabApi/app/api/requests"
	"github.com/gin-gonic/gin"
	"github.com/thedevsaddam/govalidator"
)

type SysAdd struct {
	Id       uint64 `json:"id,omitempty" valid:"id"`
	ParentId int64  `json:"parent_id,omitempty" valid:"parent_id"`
	Title    string `json:"title,omitempty" valid:"title"`
	Key      string `json:"key" valid:"key"`
	Value    string `json:"value" valid:"value"`
	State    string `json:"state" valid:"state"`
}

func CheckLogin(data interface{}, c *gin.Context) string {
	// 自定义验证规则
	rules := govalidator.MapData{
		"parent_id": []string{"required"},
		"title":     []string{"required"},
		"key":       []string{"required"},
		"value":     []string{"required"},
		"state":     []string{"required"},
	}
	// 自定义验证出错时的提示
	messages := govalidator.MapData{
		"parent_id": []string{
			"required:账号必填",
		},
		"title": []string{
			"required:账号必填",
		},
		"key": []string{
			"required:账号必填",
		},
		"value": []string{
			"required:账号必填",
		},
		"state": []string{
			"required:账号必填",
		},
	}

	errs := requests.Validate1(data, rules, messages)
	return requests.GetOneErr(errs)
}
